/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.neusoft.npi.todo.npitodo.controller;

import com.neusoft.npi.todo.npitodo.entity.CommonResult;
import com.neusoft.npi.todo.npitodo.entity.Todo;
import com.neusoft.npi.todo.npitodo.service.TodoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController // Object --- >  JSON
@RequestMapping("todo")
@Slf4j // z注入日志
@CrossOrigin("*")
public class TodoController {
    @Autowired private TodoService todoService;

    //    '/m/delete/' + todo.todoid

    @DeleteMapping("/m/delete/{todoid}")
    public CommonResult deleteTodo(@PathVariable("todoid") Integer todoid) {
        return todoService.deleteTodo(todoid);
    }

    @PutMapping("/m/finish/{todoid}")
    public CommonResult finishTodo(@PathVariable("todoid") Integer todoid) {
        return todoService.finishTodo(todoid);
    }

    @PutMapping("/m/start/{todoid}")
    public CommonResult startTodo(@PathVariable("todoid") Integer todoid) {
        return todoService.startTodo(todoid);
    }

    @PostMapping("m/add/todo")
    //    @RequestBody :JSON -- > Object
    public CommonResult addTodo(@RequestBody Todo todo) {
        System.out.println(todo);
        return todoService.addTodo(todo);
    }

    @GetMapping("q/find/all")
    public CommonResult findAll() {
        return todoService.findAll();
    }

    public CommonResult findByid(Integer tododi) {
        return null;
    }
}
